package com.gjy.concurrency.use;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * @author 宫静雨
 * @version 1.0
 * @since 2022-12-13 14:43:33
 */
public class SDFTest {

    private static final Logger logger = LoggerFactory.getLogger(SDFTest.class);

    public static void main(String[] args) {
        ThreadLocal<SimpleDateFormat> threadLocal = ThreadLocal.withInitial(() -> new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"));

        ExecutorService pool = Executors.newCachedThreadPool();
        for (int i = 0; i < 10000; i++) {
            pool.execute(() -> {
//                Date date = new Date();
//                String s = format.format(date);
                Date s;
                try {
                    s = threadLocal.get().parse("2022-11-11 22:22:22");
                    logger.info("date = {}", s);
                } catch (ParseException e) {
                    throw new RuntimeException(e);
                } finally {
                    threadLocal.remove();
                }

            });
        }

        pool.shutdown();
    }
}
